﻿# -*- coding:utf-8 -*-
import xlrd
import xlwt
from pyExcelerator import *
import re
import sys
reload(sys)
sys.setdefaultencoding('utf8') 
if __name__ == '__main__':
     
   
    file_path = 'T66_Menu_Translation.xls'
    filename = open('T66_Menu_Translation.h','w');
    filenamec = open('T66_Menu_Translation.c','w');
    filenameen = open('T66_Menu_Translation_en.h','w');
    filenamecn = open('T66_Menu_Translation_cn.h','w');
    filenamefr = open('T66_Menu_Translation_fr.h','w'); 
    filenamesp = open('T66_Menu_Translation_sp.h','w');
    bk = xlrd.open_workbook(file_path)
    shxrange = range(bk.nsheets)

    try:
        sh = bk.sheet_by_name("menu")
    except:
        print"no sheet in %s named menu" % fname
    nrows = sh.nrows
    ncols = sh.ncols
    print"nrows %d, ncols %d" % (nrows, ncols) 
    print>>filename, "#ifndef __T66_MENU_TRANSLATION_H_"
    print>>filename, "#define __T66_MENU_TRANSLATION_H_"
    print>>filename, "enum"
    print>>filename, "{"
    print>>filename, "    INVALID_INDEX,"+"         //   0"
    for i in range(2, nrows):
         print>>filename, "    "+sh.cell_value(i,1)+","+"         //" +str(i-1)
    print>>filename, "};"

    print>>filenamec, "#include \"var_tbl.h\""
    print>>filenamec, "#include \"T66_Menu_Translation.h\""
    print>>filenamec, "#include \"T66_Menu_Translation_en.h\""
    print>>filenamec, "#include \"T66_Menu_Translation_cn.h\""
    print>>filenamec, "#include \"T66_Menu_Translation_fr.h\""
    print>>filenamec, "#include \"T66_Menu_Translation_sp.h\""
    print>>filenamec, "const int Menu_language_max_obj_id = "+str(nrows - 2)+";" 
    print>>filenamec, "const Menu_language_st Menu_language_Descripiton[] =" 
    print>>filenamec, "{"
    print>>filenamec, "    {0,        0,       0,      0},        //    0" 
    for i in range(2, nrows):

         print>>filenameen, "const char menu_lang_en_"+str(int(sh.cell_value(i,0)))+"[]=\""+sh.cell_value(i,2)+"\";"

         fr_string = sh.cell_value(i,3); 
         fr_list = ''.join(str(list(fr_string)).replace('\\u','u').replace('[u\'','u').replace('u\'','u').replace('\',','').replace('u"','u').replace('",','').replace('\']','').replace('\\x','x').replace('uu,','uu'))

         print>>filenamecn, "const char menu_lang_cn_"+str(int(sh.cell_value(i,0)))+"[]=\""+fr_list  +"\";"
         
         fr_string = sh.cell_value(i,4);        
         #fr_list = str(list(fr_string)).replace('[','').replace(']','').replace(']','').replace('\\','').replace(',','').replace('\'','') 
         fr_list = str(list(fr_string)).replace('\\u','u').replace('[u\'','u').replace('u\'','u').replace('\',','').replace('u"','u').replace('",','').replace('\']','').replace('\\x','x').replace('uu,','uu')
         print>>filenamefr, "const char menu_lang_fr_"+str(int(sh.cell_value(i,0)))+"[]=\""+fr_list+"\";"

         fr_string = sh.cell_value(i,5);        
        #fr_list = str(list(fr_string)).replace('[','').replace(']','').replace(']','').replace('\\','').replace(',','').replace('\'','') 
         fr_list = str(list(fr_string)).replace('\\u','u').replace('[u\'','u').replace('u\'','u').replace('\',','').replace('u"','u').replace('",','').replace('\']','').replace('\\x','x').replace('uu,','uu')
         print>>filenamesp, "const char menu_lang_sp_"+str(int(sh.cell_value(i,0)))+"[]=\""+fr_list+"\";" 
 
         print>>filenamec, "    {"+"(u8*)menu_lang_en_"+ str(int(sh.cell_value(i,0)))+ \
         ",      (u8*)menu_lang_cn_"+ str(int(sh.cell_value(i,0))) \
         +",      (u8*)menu_lang_fr_"+ str(int(sh.cell_value(i,0)))+ \
         ",      (u8*)menu_lang_sp_"+ str(int(sh.cell_value(i,0)))+"}," +"//  " + str(i - 1)
    print>>filenamec, "};"

    print>>filename, "#endif"	

